<template>
  <div class="wrap header">
    <h1 class="l">
      <img class="logo" src="../assets/img/indexLogo.6f8ac4f0.png" />
    </h1>
    <div class="c">
      <ul>
        <li
          @click="$router.push('/home')"
          :class="$route.path === '/home' ? 'active' : ''"
        >
          首页
        </li>
        <li
          @click="$router.push('/Goods')"
          :class="$route.path === '/Goods' ? 'active' : ''"
        >
          全部商品
        </li>
        <li
          @click="$router.push('/User')"
          :class="$route.path === '/User' ? 'active' : ''"
        >
          个人中心
        </li>
        <li
          @click="$router.push('/Order')"
          :class="$route.path === '/Order' ? 'active' : ''"
        >
          我的订单
        </li>
        <li
          @click="$router.push('/Free')"
          :class="$route.path === '/Free' ? 'active' : ''"
        >
          专属福利
        </li>
      </ul>
    </div>
    <div class="r">
      <input
        type="text"
        placeholder="请输入要搜索的商品"
        v-model.trim="userInputSearch"
        @keyup.13="goTSearch"
      />
      <span
        ><img src="../assets/img/搜索.png" alt="" @click="goTSearch"
      /></span>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      // 这个是搜索商品的值
      userInputSearch: "",
    };
  },
  methods: {
    ...mapActions({
      asyncchanisshowToast: "toastStatus/asyncchanisshowToast",
    }),
    goTSearch() {
      if (!this.userInputSearch) {
        this.asyncchanisshowToast({
          msg: "不能输入为空",
          type: "denger",
        });
        return;
      }
      // 跳转到/goods
      this.$router.push(`/goods?keyword=${this.userInputSearch}`);
      this.userInputSearch = "";
    },
  },
};
</script>
 
<style lang = "less" scoped>
.header {
  height: 118px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .logo {
    cursor: pointer;
  }
  .c ul {
    width: 500px;
    display: flex;
    justify-content: space-between;
    .active {
      color: #0a328e;

      font-weight: 700;
    }
    li {
      cursor: pointer;
      font-size: 16px;
      font-family: SourceHanSansSC;
      font-weight: 500;
    }
  }
  .r {
    display: flex;
    input {
      width: 214px;
      height: 40px;
      border: 1px solid #dedede;
      border-radius: 20px 0px 0px 20px;
      text-indent: 1em;
    }
    span {
      width: 50px;
      height: 40px;
      background: #0a328e;
      border-radius: 0px 20px 20px 0px;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
    }
  }
}
</style>